              package com.java.diagnostics.visualizer.impl.marshalling;
              
              import com.java.diagnostics.visualizer.data.AggregateData;
              import com.java.diagnostics.visualizer.data.DataSet;
              import com.java.diagnostics.visualizer.data.SourceData;
              import com.java.diagnostics.visualizer.data.TupleData;
              import com.java.diagnostics.visualizer.data.UnstructuredData;
              import com.java.diagnostics.visualizer.data.UnstructuredDataBuilder;
              import com.java.diagnostics.visualizer.data.Variant;
              import com.java.diagnostics.visualizer.data.axes.Axis;
              import com.java.diagnostics.visualizer.data.axes.XDataAxis;
              import com.java.diagnostics.visualizer.display.DataDisplayer;
              import com.java.diagnostics.visualizer.exceptions.GCAndMemoryVisualizerException;
              import com.java.diagnostics.visualizer.exceptions.GCAndMemoryVisualizerParsedDataCorruptedException;
              import com.java.diagnostics.visualizer.factory.DataFactory;
import com.java.diagnostics.visualizer.gc.hp.parser.HPVGCParser;
import com.java.diagnostics.visualizer.gc.i5V5r4.parser.I5V5r4Parser;
import com.java.diagnostics.visualizer.gc.i5V6r1.parser.I5V6r1Parser;
import com.java.diagnostics.visualizer.gc.i5classic.parser.I5ClassicParser;
import com.java.diagnostics.visualizer.gc.iseriessupport.parser.ISeriesVGCParser;
import com.java.diagnostics.visualizer.gc.realtime.parser.RealTimeParser;
import com.java.diagnostics.visualizer.gc.realtime.parser.RealTimeParserV2;
import com.java.diagnostics.visualizer.gc.solarissupport.parser.OracleG1VGCParser;
import com.java.diagnostics.visualizer.gc.solarissupport.parser.SunVGCParser;
              import com.java.diagnostics.visualizer.impl.data.DataSetImpl;
              import com.java.diagnostics.visualizer.impl.extensions.DisplayerRegistry;
              import com.java.diagnostics.visualizer.impl.extensions.ParserRegistry;
              import com.java.diagnostics.visualizer.impl.extensions.RecommendationsRegistry;
              import com.java.diagnostics.visualizer.impl.factory.LogFactory;
              import com.java.diagnostics.visualizer.impl.properties.ExtensionEnablementPropertiesImpl;
              import com.java.diagnostics.visualizer.impl.properties.OutputPropertiesImpl;
              import com.java.diagnostics.visualizer.impl.sources.implementations.FileSourceImpl;
              import com.java.diagnostics.visualizer.impl.util.Messages;
import com.java.diagnostics.visualizer.parser.javadump.JavaDumpParser;
import com.java.diagnostics.visualizer.parser.tgc.TGCParserImpl;
import com.java.diagnostics.visualizer.parser.vgc.j9.J950VGCParser;
import com.java.diagnostics.visualizer.parser.vgc.j926.J926VGCParser;
import com.java.diagnostics.visualizer.parser.vgc.sovereign.SovereignVGCParser;
              import com.java.diagnostics.visualizer.parsers.Parser;
              import com.java.diagnostics.visualizer.postprocessing.PostProcessor;
              import com.java.diagnostics.visualizer.properties.ExtensionEnablementProperties;
              import com.java.diagnostics.visualizer.properties.OutputProperties;
              import com.java.diagnostics.visualizer.properties.OutputPropertiesListener;
import com.java.diagnostics.visualizer.recommender.AppendCommandLine;
import com.java.diagnostics.visualizer.recommender.CalculateCollectionCounts;
import com.java.diagnostics.visualizer.recommender.CalculateGCMode;
import com.java.diagnostics.visualizer.recommender.CalculateGlobalProperties;
import com.java.diagnostics.visualizer.recommender.CalculateOpinionOnTenuring;
import com.java.diagnostics.visualizer.recommender.CalculateRateOfGarbageCollection;
import com.java.diagnostics.visualizer.recommender.CheckForOptavgpause;
import com.java.diagnostics.visualizer.recommender.ConsiderFinalizers;
import com.java.diagnostics.visualizer.recommender.ConsiderFragmentation;
import com.java.diagnostics.visualizer.recommender.JavaDumpInfo;
import com.java.diagnostics.visualizer.recommender.LookForExcessiveCompaction;
import com.java.diagnostics.visualizer.recommender.LookForExcessiveSystemGCs;
              import com.java.diagnostics.visualizer.recommender.Recommendation;
import com.java.diagnostics.visualizer.recommender.memory.CalculateGlobalMemoryProperties;
import com.java.diagnostics.visualizer.recommender.memory.CalculateNurseryMemoryProperties;
import com.java.diagnostics.visualizer.recommender.memory.LookForExcessiveGC;
import com.java.diagnostics.visualizer.recommender.memory.LookForJavaHeapExhaustion;
import com.java.diagnostics.visualizer.recommender.memory.LookForLargeAllocations;
import com.java.diagnostics.visualizer.recommender.nativeMemory.LookForLeaks;
import com.java.diagnostics.visualizer.recommender.occupancy.NurseryOccupancyRecommendation;
import com.java.diagnostics.visualizer.recommender.occupancy.OccupancyRecommendation;
import com.java.diagnostics.visualizer.recommender.occupancy.TenuredOccupancyRecommendation;
import com.java.diagnostics.visualizer.recommender.pause.CalculateGMPPauseProperties;
import com.java.diagnostics.visualizer.recommender.pause.CalculateGlobalPauseProperties;
import com.java.diagnostics.visualizer.recommender.pause.CalculateMeanOverhead;
import com.java.diagnostics.visualizer.recommender.pause.CalculateNurseryPauseProperties;
import com.java.diagnostics.visualizer.recommender.pause.CalculatePartialPauseProperties;
import com.java.diagnostics.visualizer.recommender.pause.LookForLongPauses;
import com.java.diagnostics.visualizer.recommender.sovereign.AddActionCodeSummary;
import com.java.diagnostics.visualizer.recommender.sovereign.LookForActionCodes;
import com.java.diagnostics.visualizer.recommender.sovereign.LookForPinnedClasses;
              import com.java.diagnostics.visualizer.sources.Source;

//import edu.umd.cs.findbugs.ba.bcp.New; deleted by wenguang.huang










































              import java.io.BufferedReader;
              import java.io.File;
              import java.io.FileWriter;
              import java.io.IOException;
              import java.io.InputStream;
              import java.io.InputStreamReader;
              import java.rmi.server.UID;
              import java.text.MessageFormat;
              import java.util.ArrayList;
              import java.util.Iterator;
              import java.util.List;
              import java.util.logging.Level;
              import java.util.logging.Logger;

              import org.eclipse.core.runtime.IConfigurationElement;
              import org.eclipse.core.runtime.IExtension;
              import org.eclipse.core.runtime.IExtensionPoint;
              import org.eclipse.core.runtime.IExtensionRegistry;
              import org.eclipse.core.runtime.IProgressMonitor;
              import org.eclipse.core.runtime.IStatus;
              import org.eclipse.core.runtime.NullProgressMonitor;
              import org.eclipse.core.runtime.OperationCanceledException;
              import org.eclipse.core.runtime.Platform;
              import org.eclipse.core.runtime.Status;
              import org.eclipse.core.runtime.SubProgressMonitor;
              import org.eclipse.core.runtime.jobs.IJobChangeEvent;
              import org.eclipse.core.runtime.jobs.Job;
              import org.eclipse.core.runtime.jobs.JobChangeAdapter;
              import org.eclipse.swt.widgets.Display;
              import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.handlers.WizardHandler.New;
              
              public class MarshallerImpl
                implements Marshaller
              {
                private static final String GET_DATA_SET_METHOD = "getDataSet";
                private static final String POSTPROCESSOR_EXTENSION_ID = "com.java.diagnostics.visualizer.postprocessor";
                private static final String TUNING_RECOMMENDATION = "tuning.recommendation";
                private static final String PRIORITY = "priority";
                private static final String CLASS = "class";
                private static final String className = MarshallerImpl.class.getName();
                private DataDisplayer[] displayers;
                private String[] displayerNames;
                private DataSetImpl dataSet;

                private final OutputPropertiesImpl outputProperties;
                private List<Source> sources;
                private PostProcessor[] postProcessorChain;
                private static Parser[] parsers;

                private static String[] parserNames;
                private boolean[][] parserInterests;
                private static final Logger TRACE = LogFactory.getTrace(MarshallerImpl.class);
                public static final String PLUGIN_ID = "com.java.diagnostics.visualizer";
                private String outputFolder = null;
                private static final String RESULTS_FILE = "Results.html";
                private boolean isGoodMarshaller = true;
                private UID uid;
                private SourceProcessingJob latestJob;
              
                public MarshallerImpl()
                {
                  this.uid = new UID();
                  this.sources = new ArrayList();
                  this.dataSet = new DataSetImpl(this.uid);
                  this.outputProperties = new OutputPropertiesImpl(this.dataSet);
                }
              
//added by wenguang.huang 
             public static Parser[] getParsers() {
	            return parsers;
              }
             public static void setParsers(Parser[] parsers) {
	             MarshallerImpl.parsers = parsers;
              }
//added end by wenguang.huang 


                public void save()
                  throws GCAndMemoryVisualizerException
                {
                  TRACE.entering(className, "save");
                  if (this.isGoodMarshaller)
                  {
                    IStatus status = waitForDatasetUpdates();
              
                    if (this.dataSet.getVariants().length == 0) {
                      StringBuilder sourceNames = new StringBuilder();
                      String seperator = "";
                      for (int i = 0; i < this.sources.size(); i++) {
                        sourceNames.append(seperator + 
                          ((Source)this.sources.get(i)).getName());
                        seperator = " ";
                      }
              
                      if (!status.isOK()) {
                        throw new GCAndMemoryVisualizerException(
                          MessageFormat.format(Messages.getString("MarshallerImpl.1"), 
                          new Object[] { sourceNames.toString() }));
                      }
                      TRACE.warning(MessageFormat.format(
                        Messages.getString("MarshallerImpl.1"), 
                        new Object[] { sourceNames.toString() }));
                    }
              
                    if (this.outputFolder != null) {
                      File folder = new File(this.outputFolder);
              
                      if ((!folder.exists()) && (!folder.mkdirs()))
                      {
                        this.outputFolder = null;
                      }
                    }
              
                    if (this.displayers == null) {
                      initialiseDisplayers();
                    }
                    createResultsFile();
                    for (int i = 0; i < this.displayers.length; i++) {
                      DataDisplayer dataDisplayer = this.displayers[i];
                      Class displayerClass = dataDisplayer
                        .getClass();
                      String displayerClassName = displayerClass.getName();
              
                      String extension = dataDisplayer.getDefaultFileSaveExtension();
                      if (extension == null)
                        extension = "";
                      String shortName;
                      //String shortName;
                      if (this.outputFolder != null)
                        shortName = this.outputFolder + File.separator + 
                          this.displayerNames[i] + extension;
                      else {
                        shortName = this.displayerNames[i] + extension;
                      }
              
                      if (ExtensionEnablementPropertiesImpl.getDisplayerEnablementProperties()
                        .isExtensionEnabled(displayerClassName)) {
                        try {
                          dataDisplayer.display(this.dataSet, this.outputProperties);
                          dataDisplayer.save(shortName);
                        } catch (Throwable e) {
                          if (TRACE.isLoggable(Level.FINE)) {
                            e.printStackTrace();
                          }
                          TRACE.warning(MessageFormat.format(
                            "Displayer {0} reported error {1}.", 
                            new Object[] { this.displayers[i], e }));
                        }
                      }
                    }
                  }
              
                  TRACE.exiting(className, "save");
                }
              
//added by wenguang.huang 
          public DataSetImpl getDataSet() {
	              return dataSet;
                }
          public void setDataSet(DataSetImpl dataSet) {
	              this.dataSet = dataSet;
                }
//added end by wenguang.huang 


                private void createResultsFile()
                {
                  String shortName;
//          String shortName;
                  if (this.outputFolder != null)
                    shortName = this.outputFolder + File.separator + "Results.html";
                  else
                    shortName = "Results.html";
                  try
                  {
                    writeOutResource("Results.html", shortName);
                  } catch (IOException e) {
                    TRACE.log(Level.WARNING, 
                      Messages.getString("MarshallerImpl.results.failed"), e);
                  }
                }
              
                private boolean isReparsingNeeded()
                {
                  Iterator sourcesIt = this.sources.iterator();
              
                  while (sourcesIt.hasNext()) {
                    Source source = (Source)sourcesIt.next();
                    if (source.hasChangedSinceLastGet()) {
                      return true;
                    }
                  }
              
                  return false;
                }
              
                private void parseExistingSources(IProgressMonitor monitor)
                  throws GCAndMemoryVisualizerException
                {
                  TRACE.entering(className, "parseExistingSources");
                  try
                  {
                    monitor
                      .beginTask(
                      Messages.getString("MarshallerImpl.reparsing.sources"), parsers.length * 
                      this.sources.size());
              
                    this.dataSet.clear();
              
                    if (this.parserInterests == null) {
                      initialiseParserInterests();
                    }
              
                    int sourceIndex = 0;
                    Iterator sourcesIt = this.sources.iterator();
                    while (sourcesIt.hasNext()) {
                      Source source = (Source)sourcesIt.next();
                      if (monitor.isCanceled())
                        return;
                      //Source source;
                      boolean[] interests = this.parserInterests[sourceIndex];
                      parseSource(source, interests, monitor);
                      sourceIndex++;
                    }
                  } finally {
                    monitor.done(); } monitor.done();
              
                  TRACE.exiting(className, "parseExistingSources");
                }
              
                private void parseNewSource(Source source, IProgressMonitor monitor)
                  throws GCAndMemoryVisualizerException
                {
                  TRACE.entering(className, "parseNewSource");
                  try {
                    monitor
                      .beginTask(
                      Messages.getString("MarshallerImpl.parsing.new.sources"), parsers.length);
                    this.dataSet.clearPostprocessedLayer();
              
                    this.sources.add(source);
                    initialiseParserInterests();
                    parseSource(source, this.parserInterests[(this.sources.size() - 1)], monitor);
                  } finally {
                    monitor.done();
                  }
              
                  TRACE.exiting(className, "parseNewSource");
                }
              
                private void parseSource(Source source, boolean[] interests, IProgressMonitor monitor) throws GCAndMemoryVisualizerException
                {
                  source.resetPositions();
                  TRACE.finer("Preparing to parse source: " + source.getName());
              
                  monitor.setTaskName(MessageFormat.format(
                    Messages.getString("MarshallerImpl.parsing.source"), 
                    new Object[] { source.getName() }));
              
                  boolean dataParsed = false;
                  for (int i = 0; i < parsers.length; i++) {
                    Parser parser = parsers[i];
                    String className = parser.getClass().getName();
                    if (monitor.isCanceled()) {
                      return;
                    }
                    monitor
                      .subTask(
                      MessageFormat.format(
                      Messages.getString("MarshallerImpl.parsing.with.parser"), new Object[] { parserNames[i] }));
                      SourceData sourceData = null;
              
                    //if (ExtensionEnablementPropertiesImpl.getParserEnablementProperties()
                    //  .isExtensionEnabled(className)) 
                  {
                      interests[i] = isParseableSource(source, parser);
                      if (interests[i]) {
                        TRACE.finer("Giving parser " + parsers[i] + 
                          " a chance at source " + source.getName());
              
                        sourceData = parser.parse(source, this.outputProperties);
                        if (monitor.isCanceled()) {
                          return;
                        }
                        if ((sourceData != null) && (!sourceData.isEmpty()))
                        {
                          if ((source instanceof FileSourceImpl)) {
                            FileSourceImpl fileSource = (FileSourceImpl)source;
                            String fullPath = fileSource.getFile()
                              .getAbsolutePath();
                            sourceData.getVariantLevelData().setComment(
                              fullPath);
                          }
                          this.dataSet.addSourceData(sourceData);
                       
                          dataParsed = true;
                        }
                      }
                    }
                    monitor.worked(1);
                  }
              
                  if (!dataParsed)
                    this.sources.remove(source);
                }
              
                private void initialiseParserInterests()
                {
                  boolean[][] oldInterests = this.parserInterests;
              
                  this.parserInterests = new boolean[this.sources.size()][parsers.length];
              
                  for (int i = 0; i < this.parserInterests.length; i++)
                    if ((oldInterests != null) && (oldInterests.length > i)) {
                      this.parserInterests[i] = oldInterests[i];
                    } else {
                      boolean[] array = this.parserInterests[i];
                      for (int j = 0; j < array.length; j++)
                        array[j] = true;
                    }
                }
              
//edited by wenguang.huang 
                public boolean isParseableSource(Source source, Parser parser)
                  throws GCAndMemoryVisualizerParsedDataCorruptedException
//edited end by wenguang.huang 
                {
                  boolean isParseable = false;
                  if (parser != null) {
                    try
                    {
                      isParseable = parser.isParseableSource(source);
                    } catch (GCAndMemoryVisualizerParsedDataCorruptedException pe) {
                      throw pe;
                    } catch (Throwable e) {
                      if (TRACE.isLoggable(Level.FINE)) {
                        e.printStackTrace();
                      }
              
                      TRACE
                        .warning("Parser " + parser + " reported an error determining whether a file was parseable: " + 
                        e);
                    }
              
                  }
              
                  return isParseable;
                }
              
                private DataSetImpl postProcessData() {
                  TRACE.entering(className, "postProcessData");
              
                  if (this.postProcessorChain == null) {
                    initialisePostProcessingChain();
                  }
              
                  for (int i = 0; i < this.postProcessorChain.length; i++) {
                    if (this.postProcessorChain[i] != null)
                    {
                      String postprocessorClassName = this.postProcessorChain[i]
                        .getClass().getName();
              
                      if (ExtensionEnablementPropertiesImpl.getPostprocessorEnablementProperties()
                        .isExtensionEnabled(postprocessorClassName)) {
                        try
                        {
                          this.postProcessorChain[i].postprocess(this.dataSet, 
                            this.outputProperties);
                        }
                        catch (Throwable e)
                        {
                          TRACE.warning("Postprocessor " + this.postProcessorChain[i] + " reported error " +e);                                                                   
                          e.printStackTrace();
                        }
                      }
                    }
              
                  }
              
                  TRACE.exiting(className, "postProcessData");
                  return this.dataSet;
                }
              
                public static void runRecommendationModules(DataSetImpl dataSet, OutputProperties outputProperties)
                {
                  TRACE.entering(className, "runRecommendationModules");
//           deleted by wenguang.huang 2014年3月2日 下午8:34:11
//          RecommendationsRegistry registry = 
//            RecommendationsRegistry.getInstance();
//          Recommendation[] recommendations = registry
//            .instantiateRecommendations();
//          if (recommendations == null) {
//            return;
//          }
               
                  boolean cropped = false;
                  if (dataSet.dataIsCropped(outputProperties)) {
                    cropped = true;
                  }
              //added by wenguang.huang 2014年3月2日 下午7:36:50
              List classes = new ArrayList();
              classes.add(new CalculateRateOfGarbageCollection());
              classes.add(new CalculateGCMode());
              classes.add(new CalculateCollectionCounts());
              classes.add(new CalculateMeanOverhead());
              classes.add(new CalculateGlobalProperties());

              classes.add(new CalculateOpinionOnTenuring());
              classes.add(new CheckForOptavgpause());
              classes.add(new LookForPinnedClasses());
              classes.add(new ConsiderFragmentation());
              classes.add(new ConsiderFinalizers());

              classes.add(new LookForLargeAllocations());

              classes.add(new AppendCommandLine());
              classes.add(new LookForExcessiveCompaction());
              classes.add(new LookForExcessiveSystemGCs());
              
              classes.add(new LookForLongPauses());
              classes.add(new LookForActionCodes());
              
              classes.add(new AddActionCodeSummary());
              classes.add(new NurseryOccupancyRecommendation());
              
              classes.add(new TenuredOccupancyRecommendation());
              classes.add(new OccupancyRecommendation());
              
              classes.add(new CalculateGlobalMemoryProperties());
              classes.add(new CalculateNurseryMemoryProperties());
              
              classes.add(new CalculateNurseryPauseProperties());
              classes.add(new CalculatePartialPauseProperties());
              
              classes.add(new CalculateGMPPauseProperties());
              classes.add(new CalculateGlobalPauseProperties());
              
              classes.add(new LookForLeaks());
              classes.add(new LookForExcessiveGC());
              classes.add(new JavaDumpInfo());
              
              classes.add(new LookForJavaHeapExhaustion());
              try {
				classes.add(Class.forName("com.java.diagnostics.visualizer.recommender.sovereign.LookForJavaHeapExhaustion").newInstance());
				classes.add(Class.forName("com.java.diagnostics.visualizer.recommender.nativeMemory.LookForNativeMemoryExhaustion").newInstance());
				classes.add(Class.forName("com.java.diagnostics.visualizer.recommender.memory.FindLargestAllocation").newInstance());
				classes.add(Class.forName("com.java.diagnostics.visualizer.recommender.memory.LookForMemoryLeak").newInstance());
				classes.add(Class.forName("com.java.diagnostics.visualizer.recommender.balanced.LookForJavaHeapExhaustion").newInstance());
				classes.add(Class.forName("com.java.diagnostics.visualizer.recommender.balanced.CalculateGMPCycleCounts").newInstance());
				classes.add(Class.forName("com.java.diagnostics.visualizer.recommender.balanced.NumaObservation").newInstance());
				classes.add(Class.forName("com.java.diagnostics.visualizer.recommender.balanced.LookForJNIWarning").newInstance());
				
				classes.add(Class.forName("com.java.diagnostics.visualizer.recommender.balanced.NumaNonLocalPercentWarning").newInstance());
				classes.add(Class.forName("com.java.diagnostics.visualizer.recommender.balanced.ArrayletleafObservation").newInstance());
				classes.add(Class.forName("com.java.diagnostics.visualizer.recommender.balanced.LookForWarningsInPartials").newInstance());
				classes.add(Class.forName("com.java.diagnostics.visualizer.recommender.balanced.CheckGMPDutyTime").newInstance());
				classes.add(Class.forName("com.java.diagnostics.visualizer.recommender.balanced.LookForLongGlobalsAfterAF").newInstance());
				classes.add(Class.forName("com.java.diagnostics.visualizer.recommender.switchToBalanced.LookForLongGlobals").newInstance());
				classes.add(Class.forName("com.java.diagnostics.visualizer.recommender.switchToBalanced.LookForLongPauses").newInstance());
				classes.add(Class.forName("com.java.diagnostics.visualizer.recommender.switchToBalanced.LookforExcessiveClassUnloading").newInstance());
	
				classes.add(Class.forName("com.java.diagnostics.visualizer.recommender.switchToBalanced.LookForLargeAllocations").newInstance());
				classes.add(Class.forName("com.java.diagnostics.visualizer.recommender.switchToBalanced.LookForGCPercolated").newInstance());
				classes.add(Class.forName("com.java.diagnostics.visualizer.recommender.realtime.CalculateQuantumPauseProperties").newInstance());
				classes.add(Class.forName("com.java.diagnostics.visualizer.recommender.realtime.CalculateCollectionCounts").newInstance());
				classes.add(Class.forName("com.java.diagnostics.visualizer.recommender.oracle.CalculateFullPauseProperties").newInstance());
				
				classes.add(Class.forName("com.java.diagnostics.visualizer.recommender.oracle.CalculatePartialPauseProperties").newInstance());
				classes.add(Class.forName("com.java.diagnostics.visualizer.recommender.oracle.CalculateYoungPauseProperties").newInstance());

			} catch (InstantiationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

              Recommendation[] recommendations = (Recommendation[])classes.toArray(new Recommendation[0]);
            //added end by wenguang.huang 2014年3月2日 下午7:36:50


              
                  Variant[] variants = dataSet.getVariants();
                  for (int j = 0; j < variants.length; j++)
                  {
                    for (int i = 0; i < recommendations.length; i++) {
                      recommendations[i].recommend(variants[j]);
                    }
              
                    if (cropped)
                    {
                      UnstructuredData tuning = variants[j]
                        .getUnstructuredData("tuning.recommendation");
                      if (tuning == null) {
                        DataFactory factory = DataFactory.getFactory("VGC");
              
                        tuning = factory
                          .createUnstructuredData(
                          "tuning.recommendation", 
                          Messages.getString("MarshallerImpl.tuning.recommendation"));
                        variants[j].add(tuning);
                      }
              
                      TupleData[] tupleData = variants[j].getTupleData();
                      if ((tupleData != null) && (tupleData.length != 0))
                      {
                        String xMinStr = null;
                        String xMaxStr = null;
                        for (int tupleIndex = 0; tupleIndex < tupleData.length; tupleIndex++) {
                          XDataAxis xAxis = tupleData[tupleIndex].getXAxis();
                          String baseUnits = xAxis.getAxis().getBaseUnitName();
                          String actualUnits = outputProperties.getUnits(
                            xAxis.getAxis());
                          if (outputProperties.getMinimumX(baseUnits) != null) {
                            double xMin = outputProperties
                              .getMinimumX(baseUnits).doubleValue();
                            xMinStr = xAxis.formatUnconvertedWithUnits(xMin, 
                              actualUnits);
                          }
                          if (outputProperties.getMaximumX(baseUnits) != null) {
                            double xMax = outputProperties
                              .getMaximumX(baseUnits).doubleValue();
                            xMaxStr = xAxis.formatUnconvertedWithUnits(xMax, 
                              actualUnits);
                          }
                          if ((xMinStr != null) || (xMaxStr != null))
                          {
                            break;
                          }
                        }
                        if ((xMinStr == null) && (xMaxStr == null)) {
                          String warning = Messages.getString("MarshallerImpl.cropping.enabled.warning");
                          ((UnstructuredDataBuilder)tuning).addWarning(warning);
                        } else if ((xMinStr != null) && (xMaxStr == null)) {
                          String warning = 
                            MessageFormat.format(
                            Messages.getString("MarshallerImpl.cropping.enabled.min.warning"), 
                            new Object[] { xMinStr });
                          ((UnstructuredDataBuilder)tuning).addWarning(warning);
                        } else if ((xMinStr == null) && (xMaxStr != null)) {
                          String warning = 
                            MessageFormat.format(
                            Messages.getString("MarshallerImpl.cropping.enabled.max.warning"), 
                            new Object[] { xMaxStr });
                          ((UnstructuredDataBuilder)tuning).addWarning(warning);
                        } else if ((xMinStr != null) && (xMaxStr != null)) {
                          String warning = 
                            MessageFormat.format(
                            Messages.getString("MarshallerImpl.cropping.enabled.min.and.max.warning"), 
                            new Object[] { xMinStr, xMaxStr });
                          ((UnstructuredDataBuilder)tuning).addWarning(warning);
                        }
                      }
                    }
                  }
              
                  TRACE.exiting(className, "runRecommendationModules");
                }
              
                public void initialiseParsers() {
	           // deleted by wenguang.huang 
           //          ParserRegistry registry = ParserRegistry.getInstance();
                 
               List classes = new ArrayList();
               classes.add(new J950VGCParser());
               classes.add(new SovereignVGCParser());
               classes.add(new TGCParserImpl());
               classes.add(new JavaDumpParser());
               classes.add(new J926VGCParser());
               
               classes.add(new I5ClassicParser());
               classes.add(new I5V6r1Parser());
               classes.add(new I5V5r4Parser());
               classes.add(new RealTimeParser());
               classes.add(new RealTimeParserV2());
               
               classes.add(new ISeriesVGCParser());
               
               classes.add(new SunVGCParser());
               classes.add(new HPVGCParser());
               classes.add(new OracleG1VGCParser());
      
                  parsers = (Parser[])classes.toArray(new Parser[0]);
                  
                  parserNames = new String[parsers.length];
          //          for (int i = 0; i < parsers.length; i++)
                  parserNames[0] = "vgcJ9ParserName";
               parserNames[1] = "vgcSovereignParserName";
               parserNames[2] = "tcgParserName";
               parserNames[3] = "javacoreParser";
               parserNames[4] = "vgcJ926ParserName";
               parserNames[5] = "iSeriesClassicName";
               parserNames[6] = "iSeriesV6R1Name";
               parserNames[7] = "iSeriesV5R4Name";
               parserNames[8] = "realtimeV1Name";
               parserNames[9] = "realtimeV2Name";
               parserNames[10] = "name";
               parserNames[11] = "sunName";
               parserNames[12] = "hpName";
               parserNames[13] = "g1Name";
             
               
               
               
                      //registry.findExtensionByClassName(parsers[i].getClass().getName())
                      //.getAttribute("name");
                }
              
                private void initialisePostProcessingChain()
                {
                  IExtensionRegistry registry = Platform.getExtensionRegistry();
                  IExtensionPoint extensionPoint = registry.getExtensionPoint("com.java.diagnostics.visualizer.postprocessor");
                    
              
                  if (TRACE.isLoggable(Level.FINEST)) {
                    IExtensionPoint[] points = registry.getExtensionPoints();
                    for (int n = 0; n < points.length; n++) {
                      TRACE.finest("Extension point simpleIdentifier: " + points[n].getSimpleIdentifier());                        
                      TRACE.finest("Extension point uniqueIdentifier: " + points[n].getUniqueIdentifier());                        
                      TRACE.finest("Extension point label: " + points[n].getLabel());
                    }
                  }
              
                  if (extensionPoint != null) {
                    IExtension[] extensions = extensionPoint.getExtensions();
                    this.postProcessorChain = new PostProcessor[extensions.length];
              
                    int index = 0;
                    index = getPostProcessorsOfGivenPriority(extensions,"first", index); 
                      
                    index = getPostProcessorsOfGivenPriority(extensions, "high", index);
                      
                    index = getPostProcessorsOfGivenPriority(extensions, "medium", index);
                      
                    index = getPostProcessorsOfGivenPriority(extensions, "low", index);
                      
                    index = getPostProcessorsOfGivenPriority(extensions, "last", index);
                      
                  } else {
                    this.postProcessorChain = new PostProcessor[0];
                  }
                }
              
                private int getPostProcessorsOfGivenPriority(IExtension[] extensions, String targetPriority, int startIndex)
                {
                  int index = startIndex;
                  for (int i = 0; i < extensions.length; i++)
                  {
                    IExtension extension = extensions[i];
                    TRACE.finer("Inspecting extension: " + extension);
                    IConfigurationElement[] elements = extension
                      .getConfigurationElements();
              
                    for (int j = 0; j < elements.length; j++) {
                      IConfigurationElement element = elements[j];
                      TRACE.finer("Inspecting element: " + element.toString());
              
                      if (TRACE.isLoggable(Level.FINEST)) {
                        String[] names = element.getAttributeNames();
                        for (int n = 0; n < names.length; n++) {
                          TRACE.finest("Attribute name: " + names[n]);
                        }
              
                      }
              
                      String priority = element.getAttribute("priority");
              
                      if (((priority == null) && 
                        (targetPriority.equals("medium"))) || 
                        (targetPriority.equals(priority))) {
                        String className = element.getAttribute("class");
                        try
                        {
                          this.postProcessorChain[index] = ((PostProcessor)
                            element.createExecutableExtension("class"));
                          index++;
                          TRACE.finer("Postprocessor is " + className);
                        } catch (Throwable localThrowable) {
                          TRACE
                            .warning(
                            Messages.getString("Marshaller.postprocessor.instantiation.warning") + 
                            className);
                        }
                      }
                    }
              
                  }
              
                  return index;
                }
              
                private void initialiseDisplayers() {
                  DisplayerRegistry registry = DisplayerRegistry.getInstance();
                  this.displayers = registry.instantiateDisplayers();
                  this.displayerNames = registry.getNames();
                }
              
                public DataSet getDataSet(DataSetListener listener)
                {
                  TRACE.entering(className, "getDataSet");
              
                  if (listener != null) {
                    this.dataSet.addDataSetListener(listener);
                  }
              
                  TRACE.exiting(className, "getDataSet");
              
                  return this.dataSet;
                }
              
                public OutputProperties getOutputProps(OutputPropertiesListener listener)
                {
                  this.outputProperties.addListener(listener);
                  return this.outputProperties;
                }
              
                public void addSource(Source source)
                  throws GCAndMemoryVisualizerParsedDataCorruptedException
                {
                  processSourcesAsynchronously(
                    Messages.getString("MarshallerImpl.add.source.job.title"), source, 
                    false);
                }
              
                public void setOutputFolder(String name)
                {
                  this.outputFolder = name;
                }
              
                public void removeSource(Source source)
                {
                  processSourcesAsynchronously(
                    Messages.getString("MarshallerImpl.remove.source.job.title"), source, 
                    true);
                }
              
                public void setImageSize(int width, int height)
                {
                  this.outputProperties.setSaveWidth(Integer.valueOf(width));
                  this.outputProperties.setSaveHeight(Integer.valueOf(height));
                }
              
                private synchronized void processSources(Source source, boolean remove, IProgressMonitor monitor)
                  throws GCAndMemoryVisualizerException
                {
                  if (monitor == null) {
                    monitor = new NullProgressMonitor();
                  }
              
                  if (parsers == null) {
                    initialiseParsers();
                  }
              
                  boolean reparseSources = isReparsingNeeded();
                  boolean runPostProcessors = false;
              
                  int parsedSourcesCount = this.sources.size() * parsers.length;
                  int tickCount = 1;
              
                  if (reparseSources) {
                    tickCount += parsedSourcesCount;
                    runPostProcessors = true;
                  }
              
                  if (source != null) {
                    if (remove) {
                      tickCount++;
                    } else {
                      tickCount += parsers.length;
                      runPostProcessors = true;
                    }
                  }
              
                  if (runPostProcessors) {
                    tickCount++;
                  }
                  try
                  {
                    this.outputProperties.disableNotifications();
              
                    monitor.beginTask(
                      Messages.getString("MarshallerImpl.parsing.sources"), tickCount);
              
                    if ((remove) && (source != null)) {
                      this.dataSet.removeVariant(source.getVariantIdentifier());
                      this.sources.remove(source);
                      monitor.worked(1);
                    }
              if (monitor.isCanceled());
                    do {
                      do { do { //return;
              
                          if (reparseSources) {
                            this.dataSet.switchToParsing();
                            parseExistingSources(new SubProgressMonitor(monitor, 
                              parsedSourcesCount));
                          }
                        }
                        while (monitor.isCanceled());
              
                        if ((!remove) && (source != null)) {
                          this.dataSet.switchToParsing();
                          parseNewSource(source, new SubProgressMonitor(monitor, 
                            parsers.length));
                        }
                      }
                      while (monitor.isCanceled());
              
                      if (runPostProcessors) {
                        monitor.setTaskName(
                          Messages.getString("MarshallerImpl.running.postprocessors"));
                      //deleted by wenguang.huang 
                      //  postProcessData();
              
                        monitor.worked(1);
                      }
                    }
                    while (monitor.isCanceled());
              
                    monitor.setTaskName(
                      Messages.getString("MarshallerImpl.running.recommendations"));
                    this.dataSet.clearPostprocessedLayer();
                    this.dataSet.switchToPostprocessing();
                    runRecommendationModules(this.dataSet, this.outputProperties);
              
                    monitor.worked(1);
                  }
                  finally
                  {
                    if (Display.getCurrent() != null)
                    {
                      notifyListeners();
                    }
                    else {
                      Display.getDefault().syncExec(new Runnable() {
                        public void run() {
                          MarshallerImpl.this.notifyListeners();
                        }
                      });
                    }
              
                    monitor.done();
                  }
                  if (Display.getCurrent() != null)
                  {
                    notifyListeners();
                  }
                  else {
                    Display.getDefault().syncExec(new Runnable() {
                      public void run() {
                        MarshallerImpl.this.notifyListeners();
                      }
                    });
                  }
              
                  monitor.done();
                }
              
                private void notifyListeners()
                {
                  this.dataSet.notifyListeners();
                  this.outputProperties.notifyListeners();
                  this.outputProperties.enableNotifications();
                }
              
                private void processSourcesAsynchronously(String jobTitle, Source source, boolean remove)
                {
           //          if (!PlatformUI.isWorkbenchRunning()) {
                    try {
                      processSources(source, remove, null);
                    } catch (GCAndMemoryVisualizerException localGCAndMemoryVisualizerException) {
                      if (remove)
                        TRACE.log(Level.WARNING, 
                          MessageFormat.format(Messages.getString("MarshallerImpl.exception.removing.source"), 
                          new Object[] { source.getName() }));
                      else
                        TRACE.log(Level.WARNING, 
                          MessageFormat.format(Messages.getString("MarshallerImpl.exception.adding.source"), 
                          new Object[] { source.getName() }));
                    }
                    finally {
                      this.latestJob = null;
                    }
                  }
             //else {
                //    SourceProcessingJob parsingJob = new SourceProcessingJob(jobTitle, 
                //      source, remove);
                //    parsingJob.setUser(true);
                //    parsingJob.addJobChangeListener(new JobChangeAdapter()
                //    {
                //      public void done(IJobChangeEvent event) {
                //        super.done(event);
                //      }
                //    });
                //    parsingJob.schedule();
                //    this.latestJob = parsingJob;
                //  }
                //}
              
                public IStatus waitForDatasetUpdates()
                {
                  if (this.latestJob != null)
                    try {
                      Job jobToWaitFor = this.latestJob;
                      jobToWaitFor.join();
                      return jobToWaitFor.getResult();
                    }
                    catch (InterruptedException localInterruptedException)
                    {
                    }
                  return Status.OK_STATUS;
                }
              
                private void writeOutResource(String name, String newName) throws IOException
                {
                  InputStream stream = MarshallerImpl.class.getResourceAsStream(name);
                  if (stream != null) {
                    BufferedReader reader = null;
                    FileWriter writer = null;
                    try {
                      reader = new BufferedReader(new InputStreamReader(stream));
                      File newFile = new File(newName);
                      writer = new FileWriter(newFile);
                      char[] buffer = new char[1024];
                      int len = reader.read(buffer, 0, 1024);
                      while (len > -1) {
                        writer.write(buffer, 0, len);
                        len = reader.read(buffer, 0, buffer.length);
                      }
                    } finally {
                      if (writer != null) {
                        writer.close();
                      }
                      if (reader != null)
                        reader.close();
                    }
                  }
                }
              
                class SourceProcessingJob extends Job
                {
                  private Source source;
                  private boolean removeSource;
              
                  SourceProcessingJob(String jobTitle, Source inputSource, boolean remove)
                  {
                    super(jobTitle);
                    this.source = inputSource;
                    this.removeSource = remove;
                  }
              
                  protected IStatus run(IProgressMonitor monitor)
                  {
                    try {
                      MarshallerImpl.this.processSources(this.source, this.removeSource, monitor);
                    }
                    catch (GCAndMemoryVisualizerParsedDataCorruptedException e) {
                      if (this.removeSource)
                        MarshallerImpl.TRACE.log(Level.WARNING, 
                          MessageFormat.format(Messages.getString("MarshallerImpl.exception.removing.source"), 
                          new Object[] { this.source.getName() }));
                      else {
                        MarshallerImpl.TRACE.log(Level.WARNING, 
                          MessageFormat.format(Messages.getString("MarshallerImpl.exception.adding.source"), 
                          new Object[] { this.source.getName() }));
                      }
                      return new Status(4, "com.java.diagnostics.visualizer", e.getMessage(), e);
                    } catch (OperationCanceledException localOperationCanceledException) {
                      return Status.CANCEL_STATUS;
                    } catch (Exception e) {
                      return new Status(4, "com.java.diagnostics.visualizer", e.getMessage(), e);
                    }
                    if (monitor.isCanceled()) {
                      return Status.CANCEL_STATUS;
                    }
                    return Status.OK_STATUS;
                  }
                }
              }

